//UI初始化
var element ;
layui.use(['element'], function () {
    element = layui.element;
    $("#top a").each(function (index, obj) {
        var data = {
            obj: $(obj),
            element: element
        };
        $(obj).on("click", null, data, loadIframe)
    });
});
//Iframe中页面加载
var loadIframe = function (event) {
    var obj = event.data.obj;
    if(obj.data("href")!=""){
        loadIframeTab(obj.data("href"),obj.html());
    }

};
var loadIframeTab  =function (url,title){
    if(url==null || url==undefined){
        //无URL忽略
        return ;
    }
    var tab = $("div[lay-filter='tabPage'] li[lay-id='" + url + "']");
    if(title==undefined){
        title=url;
    }
    if (tab.length == 0) {
        element.tabAdd('tabPage', {
            title: title,
            content: "<iframe name='iframe_content' src='" + url + "' frameborder='0'/>",
            id: url
        });

    }
    resizeIframe();
    $("#top .layui-this").removeClass("layui-this");
    element.tabChange('tabPage', url);
};
var closeCurrentIframeTab = function(){
    var layId = $(".layui-this",".layui-tab").attr("lay-id");
    element.tabDelete('tabPage', layId);
}
//重新计算宽高，占满全屏
var resizeIframe = function () {
    //tab height=40 border =1 ,tab-content:padding 10
    var winHei = $(window).height() - $("#top").height() - 40 - 4;
    var winWid = $(window).width();
    var $iframe = $("iframe[name='iframe_content']");
    $iframe.each(function (index, obj) {
        $obj = $(obj);
        $obj.height(winHei);
        $obj.width(winWid);
    });
};